package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author hu
 * @date 2025/1/29
 */
@Mapper
public interface EmpMapper {

//    @Select("select count(*) from emp left join dept d on emp.dept_id = d.id")
//    public Long count();
//
//    @Select("select e.*,d.name deptName from emp e left join dept d on d.id = e.dept_id order by e.update_time desc limit #{start},#{pageSize}")
//    public List<Emp> listAllEmp(Integer start,Integer pageSize);


//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id order by entry_date desc ")


    //    public List<Emp> listAllEmp(String name, Integer gender, LocalDate begin, LocalDate end);
    public List<Emp> listAllEmp(EmpQueryParam empQueryParam);

    void deleteEmpByIds(Integer[] ids);


    @Options(useGeneratedKeys = true, keyProperty = "id")  //获取生成的主键，主键返回-mybatis的
    @Insert("insert into emp (username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time)\n" +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void save(Emp emp);


    Emp selectById(Integer id);

    void updateById(Emp empp);

    @MapKey("jobs") //可以省略 idea误报的
    List<Map<String, Object>> countJobData();

    @MapKey("name") //可以省略 idea误报的
    List<Map<String, Object>> countGenderData();

    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp selectByUsernameAndPassword(Emp emp);
}
